<?php
/**
 * Created by PhpStorm.
 * Adminuser: ERHAO
 * Date: 2018/7/31
 * Time: 16:34
 */
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Session;
class Login extends Controller
{
    //    登录页面
    public function index(){
        return $this->fetch();
    }

    public function login(){
        return $this->fetch();
    }

    //    验证登录
    public function login_check(){
        $code=input('post.yzm');
        $username=input('post.username');
        $password=md5(input('post.userpwd'));
        if(captcha_check($code)){
            $where['username'] =  $username;
            $where['pass'] =  $password;
            $where['status'] = 1;
            $res=Db::table('adminuser')->where($where)->select();
            if ($res){
                $clientIp = $this->request->ip();
                Db::table('adminuser')->where($where)->update(['ip'=>$clientIp]);
                Session::set('username',$username);
                Session::set('ip',$clientIp);
                return 1;
            }else{
                return "账号或密码错误";
            }
        }else{
            return "验证码错误";
        }
    }
    //退出登录
    public function loginout(){
        Session::clear();
        $this->success("退出成功",'admin/login/login');
    }
}